// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import Vuex from 'vuex'
window.Promise = require('promise');

Vue.prototype.$axios = axios
axios.defaults.timeout = 600000;
// axios.defaults.baseURL = 'http://api.app.test/api/';//配置请求根路径
axios.defaults.baseURL = 'http://api.uicic.com/api/';//配置请求根路径
axios.defaults.headers.common['Authorization'] = 'Bearer ' + window.localStorage.getItem('access_token');
axios.defaults.headers.common['Accept'] = 'application/json';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        user_state: false,
        user_id:'',
        name: '',
        mobile: '',
        thumb:'static/images/head.png',
        article_count: 0,
        like_user_count: 0,
        fans_count: 0,
    },
    getters:{
        user_state:state => {
          return state.user_state
      },
        user_id:state=>{
            return state.user_id;
        },
        thumb:state=>{
            return state.thumb;
        }

    },

    mutations: {
        userInfo(state, data) {
            state.user_id =data.user_id
            state.thumb = (data.thumb == null) ? 'static/images/head.png' : data.thumb
            state.name = (data.name == null) ? "匿名" : data.name
            state.mobile = data.mobile
            state.article_count = data.article_count
            state.like_user_count = data.like_user_count
            state.fans_count = data.fans_count
            state.user_state = true

        },
        logout(state) {
            state.name = ''
            state.mobile = ''
            state.article_count = 0
            state.like_user_count = 0
            state.fans_count = 0
            state.user_state = false
            window.localStorage.clear()
        }

    }
})

Vue.prototype.$store = store;

new Vue({
    el: '#app',
    router,
    components: {App},
    template: '<App/>'
})